如何使用VBA禁用保存和另存为

您所在的位置:网站首页 vba 保存 如何使用VBA禁用保存和另存为

如何使用VBA禁用保存和另存为

#如何使用VBA禁用保存和另存为| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

I am writing a macro and I need to disable the save function on the workbook that VBA has copied and pasted all the information into. Is this possible?

推荐答案

You can use the Application object to access the toolbar buttons directly:

Private Sub Workbook_Open() Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False End Sub 其他推荐答案

You can use the Workbook_BeforeSave event to achieve this, disabling the CommandBars won't stop your users using a shortcut such as CTRL + S.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) MsgBox "You can't save this workbook!" Cancel = True End Sub 其他推荐答案

One more side note; I had difficulties with the above codes because my organization uses HUNGARIAN version of Excel. So in case you use NON ENGLISH EXCEL you must specify the Controls elements in your Excel's local language ... in my case what worked was:

Application.CommandBars("Worksheet Menu Bar").Controls("Fá&jl").Controls("Menté&s má&ské&nt...").Enabled = False Application.CommandBars("Worksheet Menu Bar").Controls("Fá&jl").Controls("Menté&s").Enabled = False



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3